import * as func from "./func.js"
export default {
  name: '',
  components:{},
  data(){
    return {
      worker: null,
      result: '',
      isComputing: false // 是否在计算中
    }
  },
  methods:{
    ...func,
  },
  created(){
    // 创建 Worker 实例!!!!! 注意，worker.js需要放在public目录下面，否则找不到
    this.worker = new Worker('/worker.js')
    // 监听 Worker 返回的消息
    this.worker.onmessage = event =>  {
      const result = event.data
      this.result = `${result}`
    }
    this.worker.onerror = error => {
      this.result = `${error}`
    }
  },
  mounted(){
    
  },
  beforeDestroy() {
    // 在组件销毁前，终止 Worker
    if (this.worker) {
      this.worker.terminate();
    }
  }
}